package com.itheima.stock.controller;

import com.itheima.stock.pojo.entity.SysUser;
import com.itheima.stock.servier.UserService;
import com.itheima.stock.vo.req.LoginReqVo;
import com.itheima.stock.vo.resp.LoginRespVo;
import com.itheima.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api")
@Api(tags = "用户相关接口处理")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 根据用户名称返回用户信息
     * @param uName
     * @return
     */
    @ApiOperation(value = "根据用户名查询用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name" ,value = "用户名",dataType = "String",required = true,type = "path")
    })
    @GetMapping("/user/{userName}")
    //@PathVariable 获取路径变量
    public SysUser getUserByName(@PathVariable("userName")String uName){
        return userService.findByUserName(uName);
    }

    /**
     * 用户登录
     * @param loginReqVo
     * @return
     */

    @ApiOperation(value = "用户登录")
    @PostMapping("login")
    @ApiImplicitParam(required = true,dataType = "LoginReqVo",type = "body")
    public R<LoginRespVo> login(@RequestBody LoginReqVo loginReqVo){

        return userService.login(loginReqVo);
    }

    /**
     * 验证码
     */

    @ApiOperation("验证码生成")
    @GetMapping("/captcha")
    public R<Map> getCaptchaCode(){
        return userService.getCaptchaCode();
    }
}

















